package com.jy.adscm.wechat.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.wechat.bean.WechatPartsDetail;
import com.jy.adscm.wechat.service.WechatPartsDetailService;
import com.jy.adscm.wechat.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-09-30
 */
@RestController
@RequestMapping("/adscm/wechat/wechatPartsDetail")
public class WechatPartsDetailController {
    @Autowired
    private RedisOperator redis;
    @Autowired
    WechatPartsDetailService wechatPartsDetailService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody WechatPartsDetail wechatPartsDetail, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        Boolean result=  wechatPartsDetailService.insertWechatPartsDetail(wechatPartsDetail,openid);
        return  new SimpleCoreResponse("200","新增成功",result);
    }
    @RequestMapping("selectByPid/{pid}")
    public SimpleCoreResponse selectByPid(@PathVariable Long pid, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        List<WechatPartsDetail> wechatPartsDetails=  wechatPartsDetailService.selectByPid(pid);
        return  new SimpleCoreResponse("200","新增成功",wechatPartsDetails);
    }
}

